package designs.models.composite;

import java.util.Iterator;

public class ComputerSalary {
	public static double computerSalary(MilitaryPerson person) {
		double sum = 0;
		if (person.isLeaf() == true) {
			sum+=person.getSalary();
		}
		
		if (person.isLeaf() == false) {
			sum += person.getSalary();
			Iterator<MilitaryPerson> allChild = person.getAllChild();
			while (allChild.hasNext()) {
				MilitaryPerson militaryPerson = (MilitaryPerson) allChild.next();
				sum+=computerSalary(militaryPerson);
			}
		}
		return sum;
	}
}
